package repository

import (
	"context"
	"github.com/aphasia51/website/internal/domain"
	"github.com/aphasia51/website/internal/repository/dao"
)

type EquipmentRepository struct {
	dao *dao.EquipmentDAO
}

func NewEquipmentRepository(dao *dao.EquipmentDAO) *EquipmentRepository {
	return &EquipmentRepository{
		dao: dao,
	}
}

func (cr *EquipmentRepository) Query(ctx context.Context, c domain.Equipment) ([]domain.Equipment, error) {
	Equipments, err := cr.dao.Query(ctx, c)
	if err != nil {
		return []domain.Equipment{}, nil
	}

	returnValue := make([]domain.Equipment, 0)
	for _, v := range Equipments {
		returnValue = append(returnValue, domain.Equipment{
			Name:     v.Name,
			DictName: v.DictName,
			Stock:    v.Stock,
			//Classification:    v.Classification,
			//SerialNumber:      v.SerialNumber,
			//Price:             v.Price,
			//StoragePlace:      v.StoragePlace,
			//ManufacturingDate: v.ManufacturingDate,
		})
	}

	return returnValue, nil
}

func (cr *EquipmentRepository) Select(ctx context.Context) ([]domain.Equipment, error) {
	Equipments, err := cr.dao.Select(ctx)
	if err != nil {
		return []domain.Equipment{}, nil
	}

	returnValue := make([]domain.Equipment, 0)
	for _, v := range Equipments {
		returnValue = append(returnValue, domain.Equipment{
			Id:       v.Id,
			Name:     v.Name,
			DictName: v.DictName,
			//Classification:    v.Classification,
			//SerialNumber:      v.SerialNumber,
			//Price:             v.Price,
			//StoragePlace:      v.StoragePlace,
			//ManufacturingDate: v.ManufacturingDate,
		})
	}

	return returnValue, nil
}
